package org.fing.edu.uy.esbadp.modules.admRequeriments.mbean;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import org.fing.edu.uy.esbadp.core.entity.DMAdpServiceRequirement;
import org.fing.edu.uy.esbadp.core.entity.DMAdpServiceRequirements;
import org.fing.edu.uy.esbadp.core.entity.MetaDataConfig;
import org.fing.edu.uy.esbadp.core.entity.PropertiesMonitoring;
import org.fing.edu.uy.esbadp.core.interfaces.IAdpServiceRequirement;
import org.fing.edu.uy.esbadp.core.registry.RegistryManager;
import org.fing.edu.uy.esbadp.modules.persistance.ServiceManagerFactory;

public class EsbServiceRequirements implements EsbServiceRequirementsMBean {

	@Override
	public List<String> getEvaluationServiceRequeriments(Long serviceId,PropertiesMonitoring properties) throws SQLException {
		List<String> ret = new LinkedList<String>();
		
		//obtengo la metadata del servicio
		MetaDataConfig metadata = ServiceManagerFactory.getServiceManager().getVirtualServiceMetadata(serviceId);
		
		//dada la lista de requerimientos de servicios vamos a procesar cuales de ellos disparan evento de adaptacion.
		DMAdpServiceRequirements requerimientos = RegistryManager.getInstance().getAdpServiceRequirements();
		for(DMAdpServiceRequirement serviceReq: requerimientos.getRequirements()){			
			//pido una instancia del requerimiento
			IAdpServiceRequirement reqImp = RegistryManager.getInstance().getAdpRequirement(serviceReq.getName());
			//chequeo si es requerida.
			if(reqImp.needRequiredAdp(metadata, properties)){
				ret.add(serviceReq.getName());
			}			
		}
		
		return ret;
	}
	
}
